<?php 
session_start();
?>
<?php
	$language = $_GET["l"];
	
	
	if ( $language == "" && ($language != "es" || $language != "en" || $language != "jp") ) $language = "en";
	require_once("inc/print_func_".$language.".php");
	require_once("inc/fight_funcs.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript"><!--
	function updateClockRound2(arrayJAVA)
	{
		cad = new String;
		// si mas de 3 digitos hay q poner : despues del primero
		for (var i = 0; i < arrayJAVA.length; i++)
		{
			cad=cad+"<img src='digits/c"+arrayJAVA[i]+".gif'>";
		}
		document.getElementById("reloj2").innerHTML=cad;
	}
	//-->
</script>
<script type="text/javascript">
// <![CDATA[
	function setLastEcho(value)
	{		
		value = value.replace(/<br>/, "");
		
		var padre = document.getElementById("lastattack");
		padre.firstChild.nodeValue = value;
	}
// ]]>
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fight</title>
<style type="text/css">
<!--
body {
	background-color: #000;
	font:11px Verdana, Helvetica, sans-serif;
	background-image: url(BoxingRing.png);
	background-repeat: no-repeat;
	background-attachment:fixed;
	background-position:center; 
}
-->
</style></head>
<body>
	<div id="floatdiv" style="font:Impact, Verdana, Helvetica, sans-serif; text-align: right; vertical-align:baseline; color:#FFF; position:absolute;width:183px;height:37px;padding:16px;background:#FFFFFF; background-image:url(timer.png);background-position:center;border:none;top:10px;left:600px"> 
    	<div id="innerClock" style="width: 120px;font:Impact, Verdana, Helvetica, sans-serif; font: bold; vertical-align:middle; height:21px; padding-left: 35px; padding-top: 10px; font-size: 14px">
        	R1 00:00 
        </div>          
    </div>
<script type="text/javascript" src="float.js"></script>
	<div id="page" style="text-align:center;">
    	<div id="reloj2">
        	reloj2
        </div>
        <br /><br />
    	<div class="wrap" style="width:600px; text-align:center; background-color:#FFF; margin-left: 446px; border: thin dashed; filter:alpha(opacity=80); -moz-opacity:.80; opacity:.80;">
            <div class="content" style="text-align:left; padding-left: 5px; ">
			<?php
				$combatLog = "";
				$skill_lvl = 10;
				//PLayer A
				$nameA = "Obi";
				$iniA = 10; //sobre 10
				$iniAini = $iniA;
				$hpA = 2000;
				$hpAcurrent = 2000;
				
				//statsA
				$strA = 10;
				$iniVelA = 10;
				$velA = 10;
				$agiA = 10;
				$wpA = 3;
				$iniWpA = $wpA;
				$NoSteelA = 3;
				$enrageA = 0;
				
				//points
				$pointsA = 0;
				$pointsB = 0;
				
				$atkA[1] = "Jab";
				$atkA[2] = "Uppercut";
				$atkA[3] = "Hook";
				$atkA[4] = "Directo";
				$typeA = "Puncher";
				$deftypeA[1] = "Footplay";
				$deftypeA[2] = "Footplay";
				$deftypeA[3] = "Footplay";
				$deftypeA[4] = "Cruz";
				$counterSkillA = 20;
				$downA = 0;
				$ropesA = 0;
				//$vAttacksA[] = "";
				
				//Player B
				$nameB = "Xel";
				$iniB = 10; //sobre 10
				$iniBini = $iniB;
				$hpB = 2000;
				$hpBcurrent = 2000;
				
				//statsB
				$strB = 10;
				$iniVelB = 10;
				$velB = 10;
				$agiB = 10;
				$wpB = 3;
				$iniwpB = $wpB;
				$NoSteelB = 3;
				$enrageB = 0;
				
				$atkB[1] = "Jab";
				$atkB[2] = "Directo";
				$atkB[3] = "Hook";
				$atkB[4] = "Uppercut";
				$typeB = "Infighter";
				$deftypeB[1] = "Peekaboo";
				$deftypeB[2] = "Peekaboo";
				$deftypeB[3] = "Footplay";
				$deftypeB[4] = "Esquiva";
				$counterSkillB = 20;
				$downB = 0;
				$ropesB = 0;
				$combo = 0;
				$last_attacker = -1;
				
				//default
				//$vAttacksB[] = "";
								
				echo "PELEA DEL MILENIO: $nameA vs $nameB<br>";
				echo "---------------------------------<br>";
				
				$_SESSION[tiempo]=0;
				$clinchfail = 0;
				$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3, 10);
				//session_write_close();	
				$arrayPics = calc_pic_timer($_SESSION[tiempo]);
				?>
				<script type="text/javascript"><!--
				var arrayJAVA = new Array
				(
				<?php
				$cadenaPics = "";
				for ( $h=0; $h < count($arrayPics); $h++ )
				{
					$cadenaPics .= "'".$arrayPics[$h]."',";
				}
				$cadenaPics .= "FIN";
				$cadenaPics = str_replace(",FIN", "", $cadenaPics);
				echo $cadenaPics;
				?>
				);
				updateClockRound2(arrayJAVA);
				//-->
                </script>
                <?php			
				
				$emp = startAttack($iniA, $iniB);
				$last_attacker = $emp;
				// before print time
				print_start_secs($_SESSION[tiempo], $combatLog);
				
				// JSCall
				/*echo '<script type="text/javascript">setLastEcho("'.$lastline.'");</script>';*/
				
				//after print time
				if ( $emp == 1 )
				{
					// Print
					print_starts_attack($nameB, $combatLog);
					
					$hit_type = checkHitType();
					$def_type = checkDefType();
					// Check if he hits with the selected attack
					if ( $deftypeA[$def_type] == "Clinch" )
					{
							$clinch = checkStrengths($strA, $strB);
							if ( $clinch )
							{
								$hit = 2;
							}
							else
							{
								$hit = 1;
								$clinchfail = 1;
							}
					} 
					else
						$hit = sucessfulAttack($atkB[$hit_type], 10, 10, $typeB, $deftypeA[$def_type], $velB, $strA, $agiA);
					//show text with attack and defense
					// before print time
					print_attack_type($nameB, $_SESSION[tiempo], $atkB[$hit_type], 1, &$combatLog);
					// after print time
					// JS Time Call
					echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", 1)</script>';
					
					if ( $hit != 2 )
						print_defense_type($nameA, $deftypeA[$def_type], &$combatLog);	
					
					if ( $hit == 1 )
					{			
						$hitdone = false;
						if ( $atkB[$hit_type] == "Jab" )
							$combo = 1;
						else
							$combo = 0;
						// With Uppers and Hooks there's a chance to hit the body or the face
						if ( $atkB[$hit_type] == "Hook" || $atkB[$hit_type] == "Uppercut" )
						{
							
							srand(time());
							$facebody = rand(1,100);
							
							if ( $facebody <= 60 )
							{
								//Body Hit
								$agiA -= 1;
								if ( $agiA <= 0 ) $agiA = 1;
															
								$velA -= 1;
								if ($velA <= 0) $velA = 1;
								
								// Show the hit in the body
								print_get_bodyhit($nameA, &$combatLog);
								$hitdone = true;
							}
						}
						// If he hasn't got hit yet means that it was a hit in the face
						if ( $hitdone == false )
						{
							$hitpoints = fight($strB, $hpAcurrent, $nameA);
							// Footplay gets 150% extra damage
							if ( $deftypeA[$def_type] == "Footplay" )
							{
								$hitpoints *= 2;
							}
							if ( $clinchfail )
							{
								$hitpoints *= 1.25;
								$clinchfail = 0;
							}
							if ( $atkB[$hit_type] == "Hook" || $atkB[$hit_type] == "Uppercut" )
							{
								$hitpoints *= 0.75;
							}
							else if ( $atkB[$hit_type] == "Jab" )
							{
								$hitpoints *= 0.50;	
							}
							$hitpoints = intval($hitpoints);
							$hpAcurrent -= $hitpoints;
							
							// Show the hit in the face
							print_get_hit($nameA, $hpA, $hpAcurrent, $hitpoints, &$combatLog);
						}

						$vAttacksB[] = $atkB[$hit_type];
						$attacker = 1;
						
						//session_start();
						$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(1,2);
						//session_write_close();
						$pointsB++;
					}
					else if ( $hit == 0 )
					{
						$combo = 0;
						$vAttacksB[] = "fail";
						// Defended Successfully and depending the defence it can be a partial or a full one
						if ( $deftypeA[$def_type] == "Peekaboo" || $deftypeA[$def_type] == "Cruz" )
						{
							$hitpoints = fight($strB, $hpAcurrent, $nameA);
							
							$hitpoints *= 0.05;
							$hitpoints = intval($hitpoints);
							$hpAcurrent -= $hitpoints;
							print_partial_defense($hpA, $hpAcurrent, $hitpoints, &$combatLog);
						}
						// Counter chance
						else if ( $deftypeA[$def_type] == "Footplay" )
						{
							//40% + SkillCounter
							srand(time());
							$counterHit = rand(1,100) + $counterSkillA;
							
							if ( $counterHit > 60 )
							{
								$hitpoints = fight($strA, $hpBcurrent, $nameB);
								$hitpoints *= 1.25;
								$hitpoints = intval($hitpoints);
								$hpBcurrent -= $hitpoints;

								// Print
								print_send_counter($nameB, $hitpoints, $combatLog);
								
								$counter = 1;
							}
							else
							{
								print_get_defense(&$combatLog);
							}
						}						
						else
							print_get_defense(&$combatLog);
							
						if ( $counter == 0 )
							$counterattack = checkAttackAfterFail();
							
						if ( $counterattack >= 10 || $counter == 1) 
						{

							//session_start();
							$_SESSION[tiempo]=$_SESSION[tiempo]+1;
							//session_write_close();
							// before print time
							print_takes_advantadge($nameA, $_SESSION[tiempo], $combatLog);
							// after print time
							// JS Time Call
							echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", 1)</script>';
							$attacker = 0;
							$counter = 0;
						}
						else
						{ 
						 	$attacker = 2;
						}
					}
					// Clinch, value == 2
					else
					{
						$vAttacksB[] = "fail";
						$combo = 0;
						$clinchtime = addTime(3, 10);
						
						// Print
						print_clinch($nameA, $clinchtime, $combatLog);
						//session_start();
						$_SESSION[tiempo]=$_SESSION[tiempo]+$clinchtime;
						//session_write_close();
						$attacker = startAttack($iniA, $iniB);
					}
					
					//Ropes Check
					if ( $deftypeA[$def_type] == "Footplay" )
					{
						srand(time());
						$checkRopes = rand(1,100);
						$goRopes = 100 - $ropesA;
						// Go Ropes
						if ( $checkRopes > $goRopes )
						{
							$ropes = 0; // the one in the ropes				
							//Free Hit
							$hit_type_extra = checkHitType();
							
							if ( $combo > 0 ) 
								$combo++;
							else if ( $combo == 0 && $atkB[$hit_type_extra] == "Jab" )
								$combo = 1;
							
							$hitpoints = fight($strB, $hpAcurrent, $nameA);
							$hitpoints *= 2; // Footplay gets 150% extra damage
							if ( $atkB[$hit_type_extra] == "Hook" || $atkB[$hit_type_extra] == "Uppercut" )
							{
								$hitpoints *= 0.75;
							}
							else if ( $atkB[$hit_type_extra] == "Jab" )
							{
								$hitpoints *= 0.50;	
							}
							$hitpoints = intval($hitpoints);
							$hpAcurrent -= $hitpoints;
							//Print
							print_ropes($nameA, $hitpoints, $combatLog);
							
							$attacker = 1; // keeps the attack since he's in the ropes
							$vAttacksB[] = $atkB[$hit_type_extra];
							//End Free Hit
						}
						else
						{
							$ropesA += 10;
							if ( $ropesB >= 10 ) $ropesB -= 10;
							$ropes = -1;
						}
					}
				}
				// Player A
				else if ( $emp == 0 )
				{
					// Print
					print_starts_attack($nameA, $combatLog);

					$hit_type = checkHitType();
					$def_type = checkDefType();
					// Check if he hits with the selected attack
					if ( $deftypeB[$def_type] == "Clinch" )
					{
							$clinch = checkStrengths($strB, $strA);
							if ( $clinch )
							{
								$hit = 2;
							}
							else
							{
								$hit = 1;
								$clinchfail = 1;
							}
					} 
					else			
						$hit = sucessfulAttack($atkA[$hit_type], 10, 10, $typeA, $deftypeB[$def_type], $velA, $strB, $agiB);
					
					// Show fight text
					// before print time
					print_attack_type($nameA, $_SESSION[tiempo], $atkA[$hit_type], 0, &$combatLog);
					// after print time
					
					// JS Time Call
					/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
$arrayPics = calc_pic_timer($_SESSION[tiempo]);
				?>
				<script type="text/javascript"><!--
				var arrayJAVA = new Array
				(
				<?php
				$cadenaPics = "";
				for ( $h=0; $h < count($arrayPics); $h++ )
				{
					$cadenaPics .= "'".$arrayPics[$h]."',";
				}
				$cadenaPics .= "FIN";
				$cadenaPics = str_replace(",FIN", "", $cadenaPics);
				echo $cadenaPics;
				?>
				);
				updateClockRound2(arrayJAVA);
				//-->
                </script>
                <?php
					
					if ( $hit != 2 )
						print_defense_type($nameB, $deftypeB[$def_type], &$combatLog);
					
					if ( $hit == 1 )
					{			
						$hitdone = false;
						if ( $atkA[$hit_type] == "Jab" )
							$combo++;
						else
							$combo = 0;
						// With Uppers and Hooks there's a chance to hit the body or the face
						if ( $atkA[$hit_type] == "Hook" || $atkA[$hit_type] == "Uppercut" )
						{
							srand(time());
							$facebody = rand(1,100);
							
							if ( $facebody <= 60 )
							{
								//Body Hit
								$agiB -= 1;
								if ( $agiB <= 0 ) $agiB = 1;
															
								$velB -= 1;
								if ($velB <= 0) $velB = 1;
								
								// Show the hit in the body
								print_get_bodyhit($nameB, &$combatLog);
								$hitdone = true;
							}
						}
						// If he hasn't got hit yet means that it was a hit in the face
						if ( $hitdone == false )
						{
							$hitpoints = fight($strA, $hpBcurrent, $nameB);
							// Footplay gets 150% extra damage
							if ( $deftypeB[$def_type] == "Footplay" )
							{
								$hitpoints *= 2;
								$hitpoints = intval($hitpoints);
							}
							if ( $clinchfail )
							{
								$hitpoints *= 1.25;
								$hitpoints = intval($hitpoints);
								$clinchfail = 0;
							}
							if ( $atkA[$hit_type] == "Hook" || $atkA[$hit_type] == "Uppercut" )
							{
								$hitpoints *= 0.75;
								$hitpoints = intval($hitpoints);
							}
							else if ( $atkB[$hit_type] == "Jab" )
							{
								$hitpoints *= 0.50;
								$hitpoints = intval($hitpoints);
							}
							$hpBcurrent -= $hitpoints;
							
							// Show the hit in the face
							print_get_hit($nameB, $hpB, $hpBcurrent, $hitpoints, &$combatLog);
						}

						$vAttacksA[] = $atkA[$hit_type];
						$attacker = 0;
						//session_start();
						$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(1,2);
						//session_write_close();
						$pointsA++;
					}
					else if ( $hit == 0 )
					{
						$combo = 0;
						$vAttacksA[] = "fail";
						// Defended Successfully and depending the defence it can be a partial or a full one
						if ( $deftypeB[$def_type] == "Peekaboo" || $deftypeB[$def_type] == "Cruz" )
						{
							$hitpoints = fight($strA, $hpBcurrent, $nameB);
							$hitpoints *= 0.05;
							$hitpoints = intval($hitpoints);
							$hpBcurrent -= $hitpoints;
							print_partial_defense($hpB, $hpBcurrent, $hitpoints, &$combatLog);
						}
						// Counter chance
						else if ( $deftypeB[$def_type] == "Footplay" )
						{
							//40% + SkillCounter
							srand(time());
							$counterHit = rand(1,100) + $counterSkillB;
							
							if ( $counterHit > 60 )
							{
								$hitpoints = fight($strB, $hpAcurrent, $nameA);
								$hitpoints *= 1.25;
								$hitpoints = intval($hitpoints);
								$hpAcurrent -= $hitpoints;
								
								// Print
								print_send_counter($nameA, $hitpoints, $combatLog);
								
								$counter = 1;
							}
							else
							{
								print_get_defense(&$combatLog);
							}
						}						
						else
							print_get_defense(&$combatLog);
						
						if ( $counter == 0 )
							$counterattack = checkAttackAfterFail();
							
						if ( $counterattack >= 10 || $counter == 1 )
						{
							//session_start();
							$_SESSION[tiempo]=$_SESSION[tiempo]+1;
							//session_write_close();
							// before print time
							print_takes_advantadge($nameB, $_SESSION[tiempo], $combatLog);
							// after print time
							
							// JS Time Call
							/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
							$arrayPics = calc_pic_timer($_SESSION[tiempo]);
							?>
							<script type="text/javascript"><!--
							var arrayJAVA = new Array
							(
							<?php
							$cadenaPics = "";
							for ( $h=0; $h < count($arrayPics); $h++ )
							{
								$cadenaPics .= "'".$arrayPics[$h]."',";
							}
							$cadenaPics .= "FIN";
							$cadenaPics = str_replace(",FIN", "", $cadenaPics);
							echo $cadenaPics;
							?>
							);
							updateClockRound2(arrayJAVA);
							//-->
							</script>
							<?php
							$attacker = 1;
							$counter = 0;
						}
						else
						{ 
							$attacker = 2;
						}
					}
					// Clinch == 2
					else
					{
						$combo = 0;
						$clinchtime = addTime(3, 10);
						// Print
						print_clinch($nameB, $clinchtime, $combatLog);
						//session_start();
						$_SESSION[tiempo]=$_SESSION[tiempo]+$clinchtime;
						//session_write_close();
						$attacker = startAttack($iniA, $iniB);
					}
					
					//Ropes Check
					if ( $deftypeB[$def_type] == "Footplay" )
					{
						srand(time());
						$checkRopes = rand(1,100);
						$goRopes = 100 - $ropesB;
						// Go Ropes
						if ( $checkRopes > $goRopes )
						{
							$ropes = 1;
							//Free Hit
							$hit_type_extra = checkHitType();
							
							if ( $combo > 0 ) 
								$combo++;
							else if ( $combo == 0 && $atkB[$hit_type_extra] == "Jab" )
								$combo = 1;
							
							$hitpoints = fight($strA, $hpBcurrent, $nameB);
							$hitpoints *= 2; // Footplay gets 150% extra damage
							if ( $atkA[$hit_type_extra] == "Hook" || $atkA[$hit_type_extra] == "Uppercut" )
							{
								$hitpoints *= 0.75;
							}
							else if ( $atkA[$hit_type_extra] == "Jab" )
							{
								$hitpoints *= 0.50;	
							}
							$hitpoints = intval($hitpoints);
							$hpBcurrent -= $hitpoints;
							// Print
							print_ropes($nameB, $hitpoints, $combatLog);
							$attacker = 0; // keeps the attack since he's in the ropes
							$vAttacksA[] = $atkA[$hit_type_extra];
							//End Free Hit
						}
						else
						{
							$ropesB += 10;
							if ( $ropesA >= 10 ) $ropesA -= 10;
							$ropes = -1;
						}
					}
					
				}
				else
				{
					// Print stare
					print_stare($nameA, $nameB, $_SESSION[tiempo], $combatLog);
					
				}
				
				sleep(2);
				$combatLog .= "SLEEP 2<br>";
				// --------------
				// Bucle Rounds
				// ----------------
				for ( $round=1; $round <=10;$round++)
				{
					// Each Round
					$TKO = false;
					$comboDownCount = 0;
					while ( $hpAcurrent > 0 && $hpBcurrent > 0 && $_SESSION[tiempo] < 180 && $TKO == false )
					{
						$comboDownCount = 0;
						if ( $attacker == 1) //ataca el B
						{
							
							$hit_type = checkHitType();
							$def_type = checkDefType();
							// Check if he hits with the selected attack
							if ( $deftypeA[$def_type] == "Clinch" )
							{
									$clinch = checkStrengths($strA, $strB);
									if ( $clinch )
									{
										$hit = 2;
									}
									else
									{
										$hit = 1;
										$clinchfail = 1;
									}
							} 
							else
							{
								// Ropes Actions
								if ( $ropes == 0 ) //enemy on the ropes
								{
									srand(time());
									$actionRopes = rand(1,100);
									if ( $actionRopes <= 60 ) 
									{
										$hit = 1; // 60% hit
									}
									else if ( $actionRopes > 60  && $actionRopes < 95 )
									{
										// 35% referee
										$hit = 2;
										$ropes = -1;
										$ropesA = 0;
										$ropesB = 0;
									}
									else
									{
										// 5% switch
										$hit = 0;
										$ropes = 1;
										$ropesA = 0;
										$ropesB = 0;
									}		  
								}
								else
								{
									// Enemy on Enrage Mode
									if ( $enrageA == 1 )
									{
										$hit = 1;
									}
									else
										$hit = sucessfulAttack($atkB[$hit_type], 10, 10, $typeB, $deftypeA[$def_type], $velB, $strA, $agiA);
								}
								// End Ropes Actions
							}
							//show text with attack and defense
							// before print time
							print_attack_type($nameB, $_SESSION[tiempo], $atkB[$hit_type], 1, &$combatLog);
							// after print time
							// JS Time Call
							/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
							$arrayPics = calc_pic_timer($_SESSION[tiempo]);
							?>
							<script type="text/javascript"><!--
							var arrayJAVA = new Array
							(
							<?php
							$cadenaPics = "";
							for ( $h=0; $h < count($arrayPics); $h++ )
							{
								$cadenaPics .= "'".$arrayPics[$h]."',";
							}
							$cadenaPics .= "FIN";
							$cadenaPics = str_replace(",FIN", "", $cadenaPics);
							echo $cadenaPics;
							?>
							);
							updateClockRound2(arrayJAVA);
							//-->
							</script>
							<?php
							
							if ( $hit != 2 )
								print_defense_type($nameA, $deftypeA[$def_type], &$combatLog);
							
							if ( $hit == 1 )
							{
								$vAttacksB[] = $atkB[$hit_type];
								$hitdone = false;
								
								// With Uppers and Hooks there's a chance to hit the body or the face
								if ( $atkB[$hit_type] == "Hook" || $atkB[$hit_type] == "Uppercut" )
								{
									
									srand(time());
									$facebody = rand(1,100);
									
									if ( $facebody <= 60 )
									{
										//Body Hit
										$agiA -= 1;
										if ( $agiA <= 0 ) $agiA = 1;
																	
										$velA -= 1;
										if ($velA <= 0) $velA = 1;
										
										//empieza do combo dentro del body
										if ( $last_attacker == $attacker && $combo > 0) 
										{
											$combo++;
										}
										if ( $combo >= 3 ) 
										{
											$docombo = 1;
											$vAttacksB[] = "fail";
										}
										else
											$docombo = 0;
																					
										// Goes DOWN
										if ( $docombo == 1 )
										{	
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
											//session_write_close();
											$downA++;
											if ( $downA == 3 ) 
											{
												// Print - down stop
												print_down_stop($nameA, $combatLog);
												$TKO = true;
												break;
											}
											else if ( 180-$_SESSION[tiempo] <= 0 )
											{
												//fin round
												
												//session_start();
												$_SESSION[tiempo]=180;
												//session_write_close();
											}
											else // process DOWN
											{
												srand(time());
												$refereeCount = rand(3,9);
												// Print down count
												print_down_count($nameA, $combatLog);
												downCount($refereeCount, $combatLog);
												print_stand($nameA, $combatLog);
												
												
												// Enrage after a DOWN
												if ( $enrageA == 0 )
												{
													srand(time());
													$checkEnrage = rand(1,100);
													$calcEnrage = 100 -  ($NoSteelA * 10);
													if ( $checkEnrage > $calcEnrage  )
													{
														$enrageA = 1;
														$iniA += 3;
														// Print enrage
														print_enrage($nameA, $combatLog);
													}
												}
												else
												{
													$iniA = $iniAini;
													$enrageA = 0;
												}
												// End Enrage
													
												// Show the hit in the body
												print_get_bodyhit($nameA, &$combatLog);
												//session_start();
												$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
												//session_write_close();
												$downthisturn = 1;
												$ropes = -1;
												$ropesA = 0;
												$ropesB = 0;
												$comboDownCount = 1;
											}
											$docombo = 0;
											$combo = 0;
										} 
										else
										{
											// Show the hit in the body
											print_get_bodyhit($nameA, &$combatLog);
										}
										//fin dentro body
										
										$hitdone = true;
									}
								}
								// If he hasn't got hit yet means that it was a hit in the face
								if ( $hitdone == false )
								{
									$hitpoints = fight($strB, $hpAcurrent, $nameA);
									// Footplay gets 150% extra damage
									if ( $deftypeA[$def_type] == "Footplay" )
									{
										$hitpoints *= 2;
										$hitpoints = intval($hitpoints);
									}
									if ( $clinchfail )
									{
										$hitpoints *= 1.25;
										$hitpoints = intval($hitpoints);
										$clinchfail = 0;
									}
									if ( $atkB[$hit_type] == "Hook" || $atkB[$hit_type] == "Uppercut" )
									{
										$hitpoints *= 0.75;
										$hitpoints = intval($hitpoints);
									}
									else if ( $atkB[$hit_type] == "Jab" )
									{
										$hitpoints *= 0.50;
										$hitpoints = intval($hitpoints);
									}
									//COMBO + DOWN
									if ( $last_attacker == $attacker && $combo > 0) 
									{
										$combo++;
									}
									else if ( $combo == 0 && $atkB[$hit_type] == "Jab" )
										$combo = 1;
									else
										$combo = 0;
									
									if ( $combo >= 3 && $atkB[$hit_type] == "Jab" )
									{
										// espera al proximo turno para combo
										$docombo = 0;
									}
									else if ( $combo >= 3 && $atkB[$hit_type] != "Jab" ) 
									{
										$hitpoints *= ( $combo * 0.5 );
										$hitpoints = intval($hitpoints);
										$docombo = 1;
										$vAttacksB[] = "fail";
									}
									else
										$docombo = 0;
									$hpAcurrent -= $hitpoints;
									
									// Goes DOWN
									if ( $docombo == 1 )
									{
										//session_start();
										$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
										//session_write_close();
										$downA++;
										if ( $downA == 3 ) 
										{
											// Print - down stop
											print_down_stop($nameA, $combatLog);
											$TKO = true;
											break;
										}
										else if ( 180-$_SESSION[tiempo] <= 0 )
										{
											//fin round
											//session_start();
											$_SESSION[tiempo]=180;
											//session_write_close();
										}
										else // process DOWN
										{
											srand(time());
											$refereeCount = rand(3,9);
											//Print awesome
											print_awesome_hit($nameA, $hitpoints, $hpA, $hpAcurrent, $combatLog);
											// Print down count
											print_down_count($nameA, $combatLog);											
											downCount($refereeCount, &$combatLog);
											print_stand($nameA, $combatLog);
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
											//session_write_close();
											
											// Enrage after a DOWN
											if ( $enrageA == 0 )
											{
												srand(time());
												$checkEnrage = rand(1,100);
												$calcEnrage = 100 -  ($NoSteelA * 10);
												if ( $checkEnrage > $calcEnrage  )
												{
													$enrageA = 1;
													$iniA += 3;
													// Print enrage
													print_enrage($nameA, $combatLog);
												}
											}
											else
											{
												$iniA = $iniAini;
												$enrageA = 0;
											}
											// End Enrage
											
											$downthisturn = 1;
											$ropes = -1;
											$ropesA = 0;
											$ropesB = 0;
											$comboDownCount = 1;
										}
										$docombo = 0;
										$combo = 0;
									}
									else
									{
										// Show the hit in the face
										print_get_hit($nameA, $hpA, $hpAcurrent, $hitpoints, &$combatLog);
									}
								}
								if ( $downthisturn )
								{
									
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3,10);
									//session_write_close();
									$last_attacker = $attacker;
									$attacker = startAttack($iniA, $iniB);
									$downthisturn = 0;
								}
								else
								{
									$last_attacker = $attacker;
									$attacker = 1;
									
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(1,2);
									//session_write_close();
								}
								$pointsB++;
							}
							else if ( $hit == 0 )
							{
								$combo = 0;
								$vAttacksB[] = "fail";
								// Defended Successfully and depending the defence it can be a partial or a full one
								if ( $deftypeA[$def_type] == "Peekaboo" || $deftypeA[$def_type] == "Cruz" )
								{
									$hitpoints = fight($strB, $hpAcurrent, $nameA);
									$hitpoints *= 0.05;
									$hitpoints = intval($hitpoints);
									$hpAcurrent -= $hitpoints;
									print_partial_defense($hpA, $hpAcurrent, $hitpoints, &$combatLog);
								}
								// Counter chance
								else if ( $deftypeA[$def_type] == "Footplay" )
								{
									//40% + SkillCounter
									srand(time());
									$counterHit = rand(1,100) + $counterSkillA;
									
									if ( $counterHit > 60 )
									{
										$hitpoints = fight($strA, $hpBcurrent, $nameB);
										$hitpoints *= 1.25;
										$hitpoints = intval($hitpoints);
										$hpBcurrent -= $hitpoints;
										
										//Print
										print_send_counter($nameB, $hitpoints, $combatLog);
										$counter = 1;
									}
									else
									{
										print_get_defense(&$combatLog);
									}
								}						
								else
									print_get_defense(&$combatLog);
									
								if ( $counter == 0 )
									$counterattack = checkAttackAfterFail();
							
								if ( $counterattack >= 10 || $counter == 1 ) 
								{
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+1;
									//session_write_close();
									// before print time
									print_takes_advantadge($nameA, $_SESSION[tiempo], $combatLog);
									// after print time
									// JS Time Call
									/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
									$arrayPics = calc_pic_timer($_SESSION[tiempo]);
									?>
									<script type="text/javascript"><!--
									var arrayJAVA = new Array
									(
									<?php
									$cadenaPics = "";
									for ( $h=0; $h < count($arrayPics); $h++ )
									{
										$cadenaPics .= "'".$arrayPics[$h]."',";
									}
									$cadenaPics .= "FIN";
									$cadenaPics = str_replace(",FIN", "", $cadenaPics);
									echo $cadenaPics;
									?>
									);
									updateClockRound2(arrayJAVA);
									//-->
									</script>
									<?php
									$last_attacker = $attacker;
									$attacker = 0;
									$counter = 0;
								}
								else
								{ 
									$attacker = 2;
								}
							}
							// Clinch  hit == 2
							else
							{
								$clinchtime = addTime(3, 10);
								// Print
								print_clinch($nameA, $clinchtime, $combatLog);
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+$clinchtime;
								//session_write_close();
								$combo = 0;
								$last_attacker = $attacker;
								$attacker = startAttack($iniA, $iniB);
							}
							
							//Ropes Check
							if ( $deftypeA[$def_type] == "Footplay" )
							{
								srand(time());
								$checkRopes = rand(1,100);
								$goRopes = 100 - $ropesA;
								// Go Ropes
								if ( $checkRopes > $goRopes )
								{
									$ropes = 0;
									//Free Hit
									$hit_type_extra = checkHitType();
									
									if ( $combo > 0) 
									{
										$combo++;
									}
									else if ( $combo == 0 && $atkB[$hit_type_extra] == "Jab" )
										$combo = 1;
									else
										$combo = 0;
									
									if ( $combo >= 3 && $atkB[$hit_type_extra] == "Jab" )
									{
										// espera al proximo turno para combo
										$docombo = 0;
									}
									else if ( $combo >= 3 && $atkB[$hit_type_extra] != "Jab" ) 
									{
										$hitpoints *= ( $combo * 0.5 );
										$docombo = 1;
										$vAttacksB[] = "fail";
									}
									else
										$docombo = 0;
									
									$hitpoints = fight($strB, $hpAcurrent, $nameA);
									$hitpoints *= 2; // Footplay gets 150% extra damage
									if ( $atkB[$hit_type_extra] == "Hook" || $atkB[$hit_type_extra] == "Uppercut" )
									{
										$hitpoints *= 0.75;
									}
									else if ( $atkB[$hit_type_extra] == "Jab" )
									{
										$hitpoints *= 0.50;	
									}
									$hitpoints = intval($hitpoints);
									$hpAcurrent -= $hitpoints;
									
									// Goes DOWN
									if ( $docombo == 1 )
									{
										
										//session_start();
										$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
										//session_write_close();
										$downA++;
										if ( $downA == 3 ) 
										{
											// Print - down stop
											print_down_stop($nameA, $combatLog);
											$TKO = true;
											break;
										}
										else if ( 180-$_SESSION[tiempo] <= 0 )
										{
											//fin round
											//session_start();
											$_SESSION[tiempo]=180;
											//session_write_close();
											
										}
										else // process DOWN
										{
											srand(time());
											$refereeCount = rand(3,9);
											// Print awesome
											print_awesome_hit($nameA, $hitpoints, $hpA, $hpAcurrent, $combatLog);
											// Print down count
											print_down_count($nameA, $combatLog);											
											downCount($refereeCount, &$combatLog);
											print_stand($nameA, $combatLog);											
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
											//session_write_close();
											
											// Enrage after a DOWN
											if ( $enrageA == 0 )
											{
												srand(time());
												$checkEnrage = rand(1,100);
												$calcEnrage = 100 -  ($NoSteelA * 10);
												if ( $checkEnrage > $calcEnrage  )
												{
													$enrageA = 1;
													$iniA += 3;
													// Print enrage
													print_enrage($nameA, $combatLog);
												}
											}
											else
											{
												$iniA = $iniAini;
												$enrageA = 0;
											}
											// End Enrage
											
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3,10);
											//session_write_close();
											$last_attacker = 1;
											$attacker = startAttack($iniA, $iniB);
											$ropes = -1;
											$ropesA = 0;
											$ropesB = 0;
											$comboDownCount = 1;
										}
										
										$ropes = -1;
										$combo = 0;
										$docombo = 0;
									
									}
									else
									{
										// Print - If not combo, go ropes
										print_ropes($nameA, $hitpoints, $combatLog);
									}
									$attacker = 1;
									$vAttacksB[] = $atkB[$hit_type_extra];
									//End Free Hit
								}
								else
								{
									$ropesA += 10;
									if ( $ropesB >= 10 ) $ropesB -= 10;
								}
							}
						}
						else if ( $attacker == 0 ) // ataca el A
						{
							$hit_type = checkHitType();
							$def_type = checkDefType();
							// Attempts to Clinch
							if ( $deftypeB[$def_type] == "Clinch" )
							{
									$clinch = checkStrengths($strB, $strA);
									if ( $clinch )
									{
										$hit = 2;
									}
									else
									{
										$hit = 1;
										$clinchfail = 1;
									}
							} 
							else	
							{
								// Ropes Actions
								if ( $ropes == 1 ) //enemy on the ropes
								{
									srand(time());
									$actionRopes = rand(1,100);
									if ( $actionRopes <= 60 ) 
									{
										$hit = 1; // 60% hit
									}
									else if ( $actionRopes > 60  && $actionRopes < 95 )
									{
										// 35% referee
										$hit = 2;
										$ropes = -1;
										$ropesA = 0;
										$ropesB = 0;
									}
									else
									{
										// 5% switch
										$hit = 0;
										$ropes = 1;
										$ropesA = 0;
										$ropesB = 0;
									}		  
								}
								else
								{
									// Enemy on Enrage Mode
									if ( $enrageB == 1 )
									{
										$hit = 1;
									}
									else
										$hit = sucessfulAttack($atkA[$hit_type], 10, 10, $typeA, $deftypeB[$def_type], $velA, $strB, $agiB);
								}
								// End Ropes Actions	
							}
							// Show fight text
							// before print time
							print_attack_type($nameA, $_SESSION[tiempo], $atkA[$hit_type], 0, &$combatLog);
							// after print time
							// JS Time Call
							/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
							$arrayPics = calc_pic_timer($_SESSION[tiempo]);
							?>
							<script type="text/javascript"><!--
							var arrayJAVA = new Array
							(
							<?php
							$cadenaPics = "";
							for ( $h=0; $h < count($arrayPics); $h++ )
							{
								$cadenaPics .= "'".$arrayPics[$h]."',";
							}
							$cadenaPics .= "FIN";
							$cadenaPics = str_replace(",FIN", "", $cadenaPics);
							echo $cadenaPics;
							?>
							);
							updateClockRound2(arrayJAVA);
							//-->
							</script>
							<?php
							
							if ( $hit != 2 )
								print_defense_type($nameB, $deftypeB[$def_type], &$combatLog);
							
							if ( $hit == 1 )
							{
								$vAttacksA[] = $atkA[$hit_type];
								$hitdone = false;
								// With Uppers and Hooks there's a chance to hit the body or the face
								if ( $atkA[$hit_type] == "Hook" || $atkA[$hit_type] == "Uppercut" )
								{
									srand(time());
									$facebody = rand(1,100);
									
									if ( $facebody <= 60 )
									{
										//Body Hit
										$agiB -= 1;
										if ( $agiB <= 0 ) $agiB = 1;
																	
										$velB -= 1;
										if ($velB <= 0) $velB = 1;
										
										//empieza do combo dentro del body
										if ( $last_attacker == $attacker && $combo > 0) 
										{
											$combo++;
										}
										if ( $combo >= 3 ) 
										{
											$docombo = 1;
											$vAttacksA[] = "fail";
										}
										else
											$docombo = 0;
																					
										// Goes DOWN
										if ( $docombo == 1 )
										{
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
											//session_write_close();
											$downB++;
											if ( $downB == 3 ) 
											{
												// Print - down stop
												print_down_stop($nameB, $combatLog);
												$TKO = true;
												break;
											}
											else if ( 180-$_SESSION[tiempo] <= 0 )
											{
												//fin round
												//session_start();
												$_SESSION[tiempo]=180;
												//session_write_close();
											}
											else // process DOWN
											{
												srand(time());
												$refereeCount = rand(3,9);
												// Print down count
												print_down_count($nameB, $combatLog);												
												downCount($refereeCount, &$combatLog);
												print_stand($nameB, $combatLog);
												// Show the hit in the body
												print_get_bodyhit($nameB, &$combatLog);
												
												//session_start();
												$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
												//session_write_close();
												
												// Enrage after a DOWN
												if ( $enrageB == 0 )
												{
													srand(time());
													$checkEnrage = rand(1,100);
													$calcEnrage = 100 -  ($NoSteelB * 10);
													if ( $checkEnrage > $calcEnrage  )
													{
														$enrageB = 1;
														$iniB += 3;
														// Print enrage
														print_enrage($nameB, $combatLog);
													}
												}
												else
												{
													$iniB = $iniBini;
													$enrageB = 0;
												}
												// End Enrage
												
												$downthisturn = 1;
												$ropes = -1;
												$ropesA = 0;
												$ropesB = 0;
												$comboDownCount = 1;
											}
											$docombo = 0;
											$combo = 0;
										} 
										else
										{
											// Show the hit in the body
											print_get_bodyhit($nameB, &$combatLog);
										}
										//fin dentro body
										$hitdone = true;
									}
								}
								// If he hasn't got hit yet means that it was a hit in the face
								if ( $hitdone == false )
								{
									$hitpoints = fight($strA, $hpBcurrent, $nameB);
									// Footplay gets 150% extra damage
									if ( $deftypeB[$def_type] == "Footplay" )
									{
										$hitpoints *= 2;
										$hitpoints = intval($hitpoints);
									}
									if ( $clinchfail )
									{
										$hitpoints *= 1.25;
										$hitpoints = intval($hitpoints);
										$clinchfail = 0;
									}
									if ( $atkA[$hit_type] == "Hook" || $atkA[$hit_type] == "Uppercut" )
									{
										$hitpoints *= 0.75;
										$hitpoints = intval($hitpoints);
									}
									else if ( $atkA[$hit_type] == "Jab" )
									{
										$hitpoints *= 0.50;
										$hitpoints = intval($hitpoints);
									}
									//COMBO + DOWN
									//$comboCalc = checkCombo( $vAttacksA );
									if ( $last_attacker == $attacker && $combo > 0) 
									{
										$combo++;
									}
									else if ( $last_attacker == $attacker && $combo == 0 && $atkA[$hit_type] == "Jab" )
										$combo = 1;
									else
										$combo = 0;
									
									if ( $combo >= 3 && $atkA[$hit_type] == "Jab" )
									{
										// espera al proximo turno para combo
										$docombo = 0;
									}
									else if ( $combo >= 3 && $atkA[$hit_type] != "Jab" ) 
									{
										$hitpoints *= ( $combo * 0.5 );
										$hitpoints = intval($hitpoints);
										$docombo = 1;
										$vAttacksA[] = "fail";
									}
									else
										$docombo = 0;
										
									$hpBcurrent -= $hitpoints;
									
									// Goes DOWN
									if ( $docombo == 1 )
									{
										//session_start();
										$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
										//session_write_close();
										$downB++;
										if ( $downB == 3 ) 
										{
											// Print - down stop
											print_down_stop($nameB, $combatLog);
											$TKO = true;
											break;
										}
										else if ( 180-$_SESSION[tiempo] <= 0 )
										{
											//fin round
											//session_start();
											$_SESSION[tiempo]=180;
											//session_write_close();
										}
										else // process DOWN
										{
											srand(time());
											$refereeCount = rand(3,9);
											// Print awesome
											print_awesome_hit($nameB, $hitpoints, $hpB, $hpBcurrent, $combatLog);
											// Print down count
											print_down_count($nameB, $combatLog);
											downCount($refereeCount, &$combatLog);
											print_stand($nameB, $combatLog);											
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
											//session_write_close();
											// Enrage after a DOWN
											if ( $enrageB == 0 )
											{
												srand(time());
												$checkEnrage = rand(1,100);
												$calcEnrage = 100 -  ($NoSteelB * 10);
												if ( $checkEnrage > $calcEnrage  )
												{
													$enrageB = 1;
													$iniB += 3;
													// Print enrage
													print_enrage($nameB, $combatLog);
												}
											}
											else
											{
												$iniB = $iniBini;
												$enrageB = 0;
											}
											// End Enrage
											
											$downthisturn = 1;
											$ropes = -1;
											$ropesA = 0;
											$ropesB = 0;
											$comboDownCount = 1;
										}
										$docombo = 0;
										$combo = 0;
									}
									else
									{
										// Show the hit in the face
										print_get_hit($nameB, $hpB, $hpBcurrent, $hitpoints, &$combatLog);
									}
								}

								if ( $downthisturn )
								{
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3,10);
									//session_write_close();
									$last_attacker = $attacker;
									$attacker = startAttack($iniA, $iniB);
									$downthisturn = 0;
								}
								else
								{
									$last_attacker = $attacker;
									$attacker = 0;
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(1,2);
									//session_write_close();
									
								}
								$pointsA++;
							}
							else if ( $hit == 0 )
							{
								$vAttacksA[] = "fail";
								$combo = 0;
								// Defended Successfully and depending the defence it can be a partial or a full one
								if ( $deftypeB[$def_type] == "Peekaboo" || $deftypeB[$def_type] == "Cruz" )
								{
									$hitpoints = fight($strA, $hpBcurrent, $nameB);
									$hitpoints *= 0.05;
									$hitpoints = intval($hitpoints);
									$hpBcurrent -= $hitpoints;
									print_partial_defense($hpB, $hpBcurrent, $hitpoints, &$combatLog);
								}
								// Counter chance
								else if ( $deftypeB[$def_type] == "Footplay" )
								{
									//40% + SkillCounter
									srand(time());
									$counterHit = rand(1,100) + $counterSkillB;
									
									if ( $counterHit > 60 )
									{
										$hitpoints = fight($strB, $hpAcurrent, $nameA);
										$hitpoints *= 1.25;
										$hitpoints = intval($hitpoints);
										$hpAcurrent -= $hitpoints;
										
										// Print
										print_send_counter($nameA, $hitpoints, $combatLog);							
										$counter = 1;
									}
									else
									{
										print_get_defense(&$combatLog);
									}
								}						
								else
									print_get_defense(&$combatLog);
									  
								if ( $counter == 0 )
									$counterattack = checkAttackAfterFail();
							
								if ( $counterattack >= 10 || $counter == 1 )  
								{
									//session_start();
									$_SESSION[tiempo]=$_SESSION[tiempo]+1;
									//session_write_close();
									// before print time
									print_takes_advantadge($nameB, $_SESSION[tiempo], $combatLog);
									// after print time
									// JS Time Call
									/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
									$arrayPics = calc_pic_timer($_SESSION[tiempo]);
									?>
									<script type="text/javascript"><!--
									var arrayJAVA = new Array
									(
									<?php
									$cadenaPics = "";
									for ( $h=0; $h < count($arrayPics); $h++ )
									{
										$cadenaPics .= "'".$arrayPics[$h]."',";
									}
									$cadenaPics .= "FIN";
									$cadenaPics = str_replace(",FIN", "", $cadenaPics);
									echo $cadenaPics;
									?>
									);
									updateClockRound2(arrayJAVA);
									//-->
									</script>
									<?php
									$last_attacker = $attacker;
									$attacker = 1;
									$counter = 0;
								}
								else
								{ 
									$combo = 0;
									$attacker = 2;
								}
							}
							// Clinch  hit == 2
							else
							{
								$clinchtime = addTime(3, 10);
								// Print
								print_clinch($nameB, $clinchtime, $combatLog);
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+$clinchtime;
								//session_write_close();
								$last_attacker = $attacker;
								$attacker = startAttack($iniA, $iniB);
							}
							//Ropes Check
							if ( $deftypeB[$def_type] == "Footplay" )
							{
								srand(time());
								$checkRopes = rand(1,100);
								$goRopes = 100 - $ropesB;
								// Go Ropes
								if ( $checkRopes > $goRopes )
								{
									$ropes = 1;
									//Free Hit
									$hit_type_extra = checkHitType();
									
									if ( $combo > 0) 
									{
										$combo++;
									}
									else if ( $combo == 0 && $atkA[$hit_type_extra] == "Jab" )
										$combo = 1;
									else
										$combo = 0;
									
									if ( $combo >= 3 && $atkA[$hit_type_extra] == "Jab" )
									{
										// espera al proximo turno para combo
										$docombo = 0;
									}
									else if ( $combo >= 3 && $atkA[$hit_type_extra] != "Jab" ) 
									{
										$hitpoints *= ( $combo * 0.5 );
										$docombo = 1;
										$vAttacksB[] = "fail";
									}
									else
										$docombo = 0;
									
									$hitpoints = fight($strA, $hpBcurrent, $nameB);
									$hitpoints *= 2; // Footplay gets 150% extra damage
									if ( $atkA[$hit_type_extra] == "Hook" || $atkA[$hit_type_extra] == "Uppercut" )
									{
										$hitpoints *= 0.75;
									}
									else if ( $atkA[$hit_type_extra] == "Jab" )
									{
										$hitpoints *= 0.50;	
									}
									$hitpoints = intval($hitpoints);
									$hpBcurrent -= $hitpoints;
									
									// Goes DOWN
									if ( $docombo == 1 )
									{
										//session_start();
										$_SESSION[tiempo]=$_SESSION[tiempo]+2; // Referee starts to count after 1 sec of the down occuring
										//session_write_close();
										$downB++;
										if ( $downB == 3 ) 
										{
											// Print - down stop
											print_down_stop($nameB, $combatLog);
											$TKO = true;
											break;
										}
										else if ( 180-$_SESSION[tiempo] <= 0 )
										{
											//fin round
											//session_start();
											$_SESSION[tiempo]=180;
											//session_write_close();
											
										}
										else // process DOWN
										{
											srand(time());
											$refereeCount = rand(3,9);
											// Print awesome
											print_awesome_hit($nameB, $hitpoints, $hpB, $hpBcurrent, $combatLog);
											// Print down count
											print_down_count($nameB, $combatLog);
											downCount($refereeCount, &$combatLog);
											print_stand($nameB, $combatLog);
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+$refereeCount;
											//session_write_close();
											
											
											// Enrage after a DOWN
											if ( $enrageB == 0 )
											{
												srand(time());
												$checkEnrage = rand(1,100);
												$calcEnrage = 100 -  ($NoSteelB * 10);
												if ( $checkEnrage > $calcEnrage  )
												{
													$enrageB = 1;
													$iniB += 3;
													// Print enrage
													print_enrage($nameB, $combatLog);
												}
											}
											else
											{
												$iniB = $iniBini;
												$enrageB = 0;
											}
											// End Enrage
											
											//session_start();
											$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3,10);
											//session_write_close();
											$last_attacker = 0;
											$attacker = startAttack($iniA, $iniB);
											$ropes = -1;
											$ropesA = 0;
											$ropesB = 0;
											$comboDownCount = 1;

										}
										
										$ropes = -1;
										$combo = 0;
										$docombo = 0;
									
									}
									else
									{
										// Print - If not combo, go ropes
										print_ropes($nameB, $hitpoints, $combatLog);
									}
									$vAttacksA[] = $atkA[$hit_type_extra];
									$attacker = 0;
									//End Free Hit
								}
								else
								{
									$ropesB += 10;
									if ( $ropesA >= 10 ) $ropesA -= 10;
								}
							}
						}
						else // se miran en plan gay
						{
							// before print time
							print_stare($nameA, $nameB, $_SESSION[tiempo], $combatLog);
							// after print time
							// JS Time Call
							/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
							$arrayPics = calc_pic_timer($_SESSION[tiempo]);
							?>
							<script type="text/javascript"><!--
							var arrayJAVA = new Array
							(
							<?php
							$cadenaPics = "";
							for ( $h=0; $h < count($arrayPics); $h++ )
							{
								$cadenaPics .= "'".$arrayPics[$h]."',";
							}
							$cadenaPics .= "FIN";
							$cadenaPics = str_replace(",FIN", "", $cadenaPics);
							echo $cadenaPics;
							?>
							);
							updateClockRound2(arrayJAVA);
							//-->
							</script>
							<?php
							//session_start();
							$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3,10);
							//session_write_close();
							$last_attacker = $attacker;
							$attacker = startAttack($iniA, $iniB);
						}
						
						sleep(2);
						$combatLog .= "SLEEP 2<br>";
						//$_SESSION['reloj'] += 1;
					} // end of while
					
					if ( $hpBcurrent <= 0 && $TKO == false )
					{
						//Check WP to see if he heroicily stands up
						$downB++;
						$combo = 0;
						//echo "<br>[DEBUG]db: $downB<br>";
						if ( $downB == 3 )
						{
							$TKO = true;
							print_down_stop($nameB, $combatLog, 1);
							break;
						}
						
						// He just fell a sec ago
						if ( $comboDownCount == 1 )
						{
							// Print stop
							print_down_stop($nameB, $combatLog, 1);
							print_ko_win($nameA, $combatLog);
							$winner = 1;
							break;
						}
						
						srand(time());
						$checkWP = rand(1,100);
						$calcHeroic = 100 -  ($wpB * 10);
						if ( $checkWP > $calcHeroic  )
						{
							$WpB--;
							$hpBcurrent = intval(0.2 * $hpB);
							if ( $hpBcurrent > $hpAcurrent )
							{
								$hpBcurrent = intval(0.8 * $hpAcurrent);
							}
							// Print down count
							print_down_count($nameB, $combatLog, 0);
							downCount(9, $combatLog);
							//session_start();
							$_SESSION[tiempo]=$_SESSION[tiempo]+9;
							//session_write_close();
							// Print heroic
							print_stand_heroic($nameB, $combatLog);
							
							// Enrage after a DOWN
							if ( $enrageB == 0 )
							{
								srand(time());
								$checkEnrage = rand(1,100);
								$calcEnrage = 100 -  ($NoSteelB * 10);
								if ( $checkEnrage > $calcEnrage  )
								{
									$enrageB = 1;
									$iniB += 3;
									// Print enrage
									print_enrage($nameB, $combatLog);
								}
							}
							else
							{
								$enrageB = 0;
								$iniB = $iniBini;
							}
							// End Enrage
							
							$heroic = true;
							$ropes = -1;
							$ropesA = 0;
							$ropesB = 0;
						}
						else
						{
							srand(time());
							$calcKO = rand(1,100);
							if ( $calcKO > 50 )
							{
								// Print down count
								print_down_count($nameB, $combatLog, 0);
								
								$stopMatch = rand(1,3);
								downCount($stopMatch, &$combatLog);
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+10;
								//session_write_close();
								// Print win
								print_stop_win($nameB, $nameA, $combatLog);
								$ropes = -1;
								$ropesA = 0;
								$ropesB = 0;
							}
							else
							{
								// Print down count
								print_down_count($nameB, $combatLog, 0);
								
								downCount(10, &$combatLog);
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+10;
								//session_write_close();
								// Print win
								print_ko_win($nameA, $combatLog);
								$ropes = -1;
								$ropesA = 0;
								$ropesB = 0;
							}
							$winner = 1;
							break;
						}
					}
					else if ( $hpAcurrent <= 0 && $TKO == false )
					{
						$combo = 0;
						$downA++;
						
						//echo "<br>[DEBUG]da: $downA<br>";
						if ( $downA == 3 )
						{
							$TKO = true;
							print_down_stop($nameA, $combatLog, 1);
							break;	
						}
						
						// He just fell a sec ago
						if ( $comboDownCount == 1 )
						{
							// Print stop
							print_down_stop($nameA, $combatLog, 1);
							print_ko_win($nameB, $combatLog);
							$winner = 1;
							break;
						}
						
						//Check WP to see if he heroicily stands up
						srand(time());
						$checkWP = rand(1,100);
						$calcHeroic = 100 -  ($wpA * 10);
						if ( $checkWP > $calcHeroic  )
						{
							$WpA--;
							$hpAcurrent = intval(0.2 * $hpA);
							if ( $hpAcurrent > $hpBcurrent )
							{
								$hpAcurrent = intval(0.8 * $hpBcurrent);
							}
							// Print down count
							print_down_count($nameA, $combatLog, 0);
							
							downCount(9, &$combatLog);
							//session_start();
							$_SESSION[tiempo]=$_SESSION[tiempo]+9;
							//session_write_close();
							// Print heroic
							print_stand_heroic($nameA, $combatLog);
							
							// Enrage after a DOWN
							if ( $enrageA == 0 )
							{
								srand(time());
								$checkEnrage = rand(1,100);
								$calcEnrage = 100 -  ($NoSteelA * 10);
								if ( $checkEnrage > $calcEnrage  )
								{
									$enrageA = 1;
									$iniA += 3;
									// Print enrage
									print_enrage($nameA, $combatLog);
								}
							}
							else
							{
								$enrageA = 0;
								$iniA = iniAini;
							}
							// End Enrage
							$heroic = true;
							$ropes = -1;
							$ropesA = 0;
							$ropesB = 0;
						}
						else
						{
							srand(time());
							$calcKO = rand(1,100);
							if ( $calcKO > 50 )
							{
								// Print down count
								print_down_count($nameA, $combatLog, 0);
							
								$stopMatch = rand(1,3);
								downCount($stopMatch, &$combatLog);
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+10;
								//session_write_close();
								// Print win
								print_stop_win($nameA, $nameB, $combatLog);	
								
								$ropes = -1;
								$ropesA = 0;
								$ropesB = 0;
							}
							else
							{
								// Print down count
								print_down_count($nameA, $combatLog, 0);
								
								downCount(10, &$combatLog);
								
								//session_start();
								$_SESSION[tiempo]=$_SESSION[tiempo]+10;
								//session_write_close();
								// Print win
								print_ko_win($nameB, $combatLog);
								$ropes = -1;
								$ropesA = 0;
								$ropesB = 0;
							}
							$winner = 1;
							break;
						}
					}
					else if ( $TKO == true )
					{	
						//echo "<br>[DEBUG] TKO=TRUE<br>";
						break;
					}		
					else
					{
						$winner = 0;
						// They heal for 10% of remaining hp
						$percentB = intval( 0.10 * $hpBcurrent );
						$hpBcurrent += $percentB;
						if ( $hpBcurrent > $hpB ) $hpBcurrent = $hpB;
						
						$percentA = intval (0.10 * $hpAcurrent);
						$hpAcurrent += $percentA;
						if ( $hpAcurrent > $hpA ) $hpAcurrent = $hpA;
						
						// Print round end - part1
						print_end_round($round, $nameA, $nameB, $percentA, $percentB, $combatLog);
						
						// Reset Stats
						if ( $velA != $iniVelA )
						{
							$velA = $iniVelA;
							// Print stats back
							print_stat_recovery($nameA, $combatLog);
						}
						if ( $velB != $iniVelB )
						{
							$velB = $iniVelB;
							// Print stats back
							print_stat_recovery($nameB, $combatLog);
						}
						// Print round end - part2
						print_end_round2($combatLog);

						// Reset round 
						$vAttacksB[] = "fail";
						$vAttacksA[] = "fail";
						$downA = 0;
						$downB = 0;
						$ropes = -1;
						$ropesA = 0;
						$ropesB = 0;
						$combo = 0;
						
						$enrageA = 0;
						$enrageB = 0;
						$iniB = $iniBini;
						$iniA = $iniAini;
						$WpA = $iniWpA;
						$WpB = $iniWpB;
						//session_start();
						$_SESSION[tiempo]=0;
						$_SESSION[tiempo]=$_SESSION[tiempo]+addTime(3, 10);
						//session_write_close();
						$attacker = startAttack($iniA, $iniB);
						$last_attacker = $attacker;
						if ( $round < 10 )
						{
							// before print time
							print_start_secs($_SESSION[tiempo], $combatLog);
							// after print time
							// JS Time Call
							/*echo '<script language="javascript">updateClockRound("'.$_SESSION[tiempo].'", '.$round.')</script>';*/
							$arrayPics = calc_pic_timer($_SESSION[tiempo]);
							?>
							<script type="text/javascript"><!--
							var arrayJAVA = new Array
							(
							<?php
							$cadenaPics = "";
							for ( $h=0; $h < count($arrayPics); $h++ )
							{
								$cadenaPics .= "'".$arrayPics[$h]."',";
							}
							$cadenaPics .= "FIN";
							$cadenaPics = str_replace(",FIN", "", $cadenaPics);
							echo $cadenaPics;
							?>
							);
							updateClockRound2(arrayJAVA);
							//-->
							</script>
							<?php
						}
					}
					
					// He stood up after a KO
					if ( $heroic )
					{
						$round--;
						$heroic = false;
					}		
					
				} //end for
				if ( $winner == 0 && $TKO == false )
				{
					// Print point winner
					print_winner_points($nameA, $nameB, $pointsA, $pointsB, $combatLog);
				}
				else if ( $TKO == true )
				{
					// Print tko win
					print_win_tko($nameA, $nameB, $downA, $combatLog);
				}
				
				/*echo "<br>****************************************<br>";
				echo "                COMBAT LOG";
				echo "<br>****************************************<br>";
				echo $combatLog;*/
				
				
				//echo "[DEBUG] $_SESSION[tiempo]<br>";
				/*echo "$nameA<br>";
				for ( $i = 0; $i < count($vAttacksA); $i++)
				{
					echo "$vAttacksA[$i]<br>";
				}
				echo "$nameB<br>";
				for ( $i = 0; $i < count($vAttacksB); $i++)
				{
					echo "$vAttacksB[$i]<br>";
				}*/
			?>  
            </div>		
    	</div>
    </div>

</body>
</html>